package com.gitee.melin.bee.core.hibernate5.type;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * @author melin 2021/9/22 1:28 下午
 */
@Converter
public class BooleanToIntConverter implements AttributeConverter<Boolean, Integer> {

    @Override
    public Integer convertToDatabaseColumn(Boolean value) {
        return (value != null && value) ? 1 : 0;
    }

    @Override
    public Boolean convertToEntityAttribute(Integer value) {
        if (value == null) {
            return false;
        }
        return 1 == value;
    }
}
